package com.lineage.data.npc.other;

import com.lineage.data.cmd.CreateNewItem;
import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_Shenter extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_Shenter.class);
  
  public static NpcExecutor get() {
    return new Npc_Shenter();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (!pc.getInventory().checkItem(95308) && !pc.getInventory().checkItem(95309)) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "shenter1"));
      } else {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "shenter2"));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
    try {
      if (cmd.equalsIgnoreCase("r")) {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("尚未开放排名"));
      } else if (cmd.equalsIgnoreCase("a")) {
        if (pc.getInventory().checkItem(95309)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("尸魂水晶还在封印中"));
          return;
        } 
        if (pc.getInventory().checkItem(95308)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("你已经领取过了"));
          return;
        } 
        if (pc.getInventory().getSize() > 170) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("你身上持有道具过多，领取失败"));
          return;
        } 
        CreateNewItem.createNewItem(pc, 95308, 1L);
        pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
